const xlsx = require('node-xlsx')
const fs = require('fs')
const { len, isLenWord ,getWordList,sum, log, search,
        soldiers, suffix,prefix,words,includes,distinct,w_ll,_a_
} = require('./utils')
const {writeXls,createXls} = require('./writeXls')
const sheets = xlsx.parse('./10530/word.xlsx')

let lists = []
/**
 * 最长的单词为16
 */
const wordList = soldiers(16)
sheets.forEach(item => {
    lists = [...lists, ...item.data]
    item.data.forEach(i =>{
        wordList.forEach((l,index)=>{
            //生成不同长度的单词list
            wordList[index] = getWordList(l,i,i[0],index+1)
        })
    })
})


const e4 = wordList[5].filter(item=>{
    return item[0].toLowerCase().endsWith('e')
})

const e5 = wordList[6].filter(item=>{
    return item[0].toLowerCase().endsWith('e')
})


// print = log('总数')
// //获取单词总数
// print('',len(lists))
// print = log('个字母')
// // 获取2个字母组成的单词
// print(2,len(w2))
// // 获取3个字母组成的单词
// print(3,len(w3))
// // 获取4个字母组成的单词
// print(4,len(w4))
// // 获取5个字母组成的单词
// print(5,len(w5))
// // 获取5个字母组成的单词
//搜索单词
// console.log(search(lists,'game'))
// console.log(len(lists) - sum(len(w2),len(w3),len(w4),len(w5)))
// console.log(len(e5))
// console.log(e5)

// 生成excel文件
let datas = []
wordList.forEach((item, index) => {
    if(index <1){
        datas = [...datas, ...item]
    }
})

// createXls(writeXls(datas),'/word/t')



// createXls(writeXls(prefix(lists,'ful')),'/word/后缀为ful')
// console.log(len(prefix(lists,'tion')))
// console.log(lists)
// console.log(prefix(lists,'ture').map(item =>{
//     return item.filter((item,index)=>{
//         return index === 0
//     }).join(',')
// }))

// console.log(len(include(lists,'ought')))
// console.log(words(prefix(lists,'all')))
// console.log(prefix(lists,'ago'))
// console.log(include(lists,'ee'))
// console.log(wordList[3].length)
// console.log(words(prefix(wordList[3],'e')))

fs.writeFile('./test.txt',distinct(_a_(lists)),(err)=>{
    if(err){
        throw err
    }
    console.log('Saved.')
})
console.log(distinct(_a_(lists)))
// console.log(wordList[1].length)
// console.log(wordList[2].length)
// console.log(wordList[5].length)
// console.log(include(lists,'ea').length)
// console.log(include(lists,'ear'))
// console.log(include(lists,'eigh').length)
// console.log(prefix(lists,'ey'))
// console.log(prefix(lists,'sug'))
// console.log(includes(lists,'or'))